package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.InfoStoreDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.KawmTypeDO;
import com.jinzhi.jzweb.service.KawmTypeService;
import com.jinzhi.common.utils.Result;

/**
 *
 * <pre>
 * 赛项类型
 * </pre>
 * <small> 2023-10-10 13:43:16 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/kawmType")
public class KawmTypeController extends BaseController {
	@Autowired
	private KawmTypeService kawmTypeService;

	@GetMapping()
	@RequiresPermissions("jzweb:kawmType:kawmType")
	String KawmType(){
		return "jzweb/kawmType/kawmType";
	}

	@ResponseBody
	@GetMapping("/list")
//	@RequiresPermissions("jzweb:kawmType:kawmType")
	public Result<Page<KawmTypeDO>> list(KawmTypeDO kawmTypeDTO){
		// 查询列表数据
		Wrapper<KawmTypeDO> wrapper = new EntityWrapper<KawmTypeDO>().orderBy("id",false);
		if(StringUtils.isNotEmpty(kawmTypeDTO.getType())){
			wrapper.eq("type",kawmTypeDTO.getType());
		}
		if(StringUtils.isNotEmpty(kawmTypeDTO.getValue())){
			wrapper.eq("value",kawmTypeDTO.getValue());
		}
		if(StringUtils.isNotEmpty(kawmTypeDTO.getSpecificType())){
			wrapper.eq("specific_type",kawmTypeDTO.getSpecificType());
		}
		Page<KawmTypeDO> page = kawmTypeService.selectPage(getPage(KawmTypeDO.class),wrapper);
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			KawmTypeDO obj = (KawmTypeDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	@GetMapping("/add")
	@RequiresPermissions("jzweb:kawmType:add")
	String add(){
		return "jzweb/kawmType/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:kawmType:edit")
	String edit(@PathVariable("id") Long id,Model model){
		KawmTypeDO kawmType = kawmTypeService.selectById(id);
		model.addAttribute("kawmType", kawmType);
		return "jzweb/kawmType/edit";
	}

	@Log("添加赛项类型")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:kawmType:add")
	public Result<String> save( KawmTypeDO kawmType){
		kawmType.setCreateTime(new Date());
		kawmTypeService.insert(kawmType);
		return Result.ok();
	}

	@Log("修改赛项类型")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:kawmType:edit")
	public Result<String>  update( KawmTypeDO kawmType){
		boolean update = kawmTypeService.updateById(kawmType);
		return update ? Result.ok() : Result.fail();
	}

	@Log("删除赛项类型")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:kawmType:remove")
	public Result<String>  remove( Long id){
		kawmTypeService.deleteById(id);
		return Result.ok();
	}

	@Log("批量删除赛项类型")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:kawmType:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		kawmTypeService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

}
